package kr.saeildadim.androidexam_saeildamil.chapter12;

import java.util.ArrayList;

import kr.saeildadim.androidexam_saeildamil.R;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Ch12_ListViewEx extends Activity {
	String[] arr;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listviewex);
		//arr= getResources().getStringArray(R.array.country);
		
		final ArrayList<String> arList = new ArrayList<String>();
		arList.add("이순신");
		arList.add("을지문덕");
		arList.add("강감찬");
		arList.add("김유신");
		arList.add("연개소문");
		arList.add("세종대왕");
		
		//String[] arList ={"이순신","강감찬","을지문덕"};
	
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
				android.R.layout.simple_list_item_1, arList);

		//ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.country, android.R.layout.simple_list_item_1);	
		
		ListView list = (ListView) findViewById(R.id.ch12_listview_list);
		list.setAdapter(adapter);
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
					String str = arList.get(position);
					Toast.makeText(Ch12_ListViewEx.this, str, Toast.LENGTH_LONG).show();
				
			}
			
		});
		
		/*		list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		list.setDivider(new ColorDrawable(Color.YELLOW));
		list.setDividerHeight(5);
*/	}
}

